<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<script>
    let obj = {
        id: 1,
        name: "haha"
    };
    const map = new Map();
    // map.set("id", 1.txt);
    // map.set("name", "haha");
    // map.set("hubby", ["java", "c++"]);
    // map.set("obj", obj);
    // map.set("name", "张三");

    map.set("id", 1).set("name", "haha").set("hubby", ["java", "c++"]).set("obj", obj).set("name", "张三");
    console.log(map);
    console.log(map.get("name"));
    console.log(map.get("hubby"));
    console.log(map.get("obj"));
    console.log(map.size);
    console.log("-------------------")
    map.forEach((value, index, self) => {
        console.log(value, index);
    })
    console.log("-------------------")
    for (let [key, value] of map) {
        console.log(key);
        console.log(value);
    }
    console.log(map.delete("name"));
    console.log(map.get("name"));
    map.clear();
    console.log(map);
    //使用场景
    let books = [
        {id: 1, name: 'Java从入门到放弃', price: 80, tdate: '2020-07-01', count: 1, email: "haha"},
        {id: 2, name: 'Vue从入门到放弃', price: 90, tdate: '2020-07-02', count: 1, email: "haha"},
        {id: 4, name: '啥都从入门到放弃', price: 70.0001, tdate: '2020-07-04', count: 1, email: "hehe"},
        {id: 5, name: 'JavaScript从入门到放弃', price: 60.00, tdate: '2020-07-04', count: 1, email: "hehe"},
        {id: 3, name: 'Mysql从入门到放弃', price: 100.01, tdate: '2020-07-03', count: 1, email: "haha"},
        {id: 6, name: 'JavaScript从入门到放弃', price: 50.00, tdate: '2020-07-04', count: 1, email: "hehe"}
    ];
    let booksMap = new Map();
    books.forEach(value => {
        map.set(value.id, value);
    });
    console.log(books.indexOf(map.get(3)));
    books.forEach((value, index) => {
        if (value.id == 3) {
            console.log(index);
        }
    });
    map.set(3, "haha");
    map.set(7, map.get(2));
    console.log(map);
    console.log(map.get(7) === map.get(2));
    console.log(new Map(books));//不能直接放数组

    let set = new Set(books);
    console.log(set);
    set.forEach((value, index) => {
        console.log(value === index);
    });
    set.add(books[0]);
    console.log(set.size);//6
    set.add(1);
    set.add(1);
    console.log(set.size);//7

</script>
</body>
</html>